package com.gxa.eloan.service.impl;

import com.gxa.eloan.mapper.TxWithdrawsMapper;
import com.gxa.eloan.pojo.PageBean;
import com.gxa.eloan.pojo.TxWithdraws;
import com.gxa.eloan.service.TxWithdrawsService;
import com.gxa.eloan.vo.CheckVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("txWithdrawsService")
public class TxWithdrawsServiceImpl implements TxWithdrawsService {
    @Resource(name = "txWithdrawsMapper")
    private TxWithdrawsMapper txWithdrawsMapper;

/*    @Transactional(propagation = Propagation.SUPPORTS)//查询适合SUPPORTS  增删改适合用REQUIRED

    public PageBean<TxWithdraws> selectByPage(int page, int limit) {
        List<TxWithdraws> txWithdraws = txWithdrawsMapper.selectByPage((page - 1) * limit, limit);
        int i = txWithdrawsMapper.selectCount();
        PageBean<TxWithdraws> pageBean = new PageBean<>();
        pageBean.setPageBean(txWithdraws);
        pageBean.setCount(i);
        return pageBean;
    }*/

    /**
     * 这是查询需要审核的方法
     * @param page
     * @param limit
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public PageBean<TxWithdraws> selectByStatus(int page, int limit) {
        List<TxWithdraws> txWithdraws = txWithdrawsMapper.selectByStatus((page-1)*limit,limit);
        int i = txWithdrawsMapper.selectCountStatus();
        PageBean<TxWithdraws> pageBean = new PageBean<>();
        pageBean.setPageBean(txWithdraws);
        pageBean.setCount(i);
        return pageBean;
    }

    @Override
    public Object[] selectById(Long id, Long userId) {
        return new Object[0];
    }

    @Override
    public int updateById(Double balance_total, double withdraws, double balancea_available, String notes, long withId, long balanId, Boolean bool) {
        return 0;
    }

    @Transactional(propagation = Propagation.SUPPORTS)//查询适合SUPPORTS  增删改适合用REQUIRED
    @Override
    public PageBean<TxWithdraws> selectByPage(CheckVo checkVo) {
        Date time =new Date("Tue Mar 26 00:00:00 CST 2019");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String timeFormat = sdf.format(time);
        System.out.println(timeFormat);

        PageBean<TxWithdraws> pageBean = new PageBean<>();
        List<TxWithdraws> txWithdraws = txWithdrawsMapper.selectByPage(checkVo);
        int i = txWithdrawsMapper.selectCount();
        pageBean.setPageBean(txWithdraws);
        pageBean.setCount(i);

        return pageBean;


    }

}
